/*
 * NetworkCheck.java
 *
 * Copyright(c) IronOne Technologies (Pvt) Ltd.  All Rights Reserved.
 * This software is the proprietary information of IronOne Technologies (Pvt) Ltd.
 *
 */

package com.ironone.streaming.comm;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * {This class shows connectivity info for the user}
 * 
 * @Created on May 21, 2014 : 4:52:00 PM
 * @author Suren Manawatta
 */
public class NetworkCheck {

	public static final int TYPE_NONE = -1;
	public static final int TYPE_MOBILE = 0;
	public static final int TYPE_WI_FI = 1;
	
	public static boolean isNetworkAvailable(Context context) {
		try {
			ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
			NetworkInfo info = manager.getActiveNetworkInfo();
			if (info != null && info.isAvailable()) {
				return true;
			}
			return false;
		} catch (Exception e) {
			return false;
		}
	}
	
	public static int getNetworkType(Context context) {
		 try {
			int type = TYPE_NONE;
			 ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
			 NetworkInfo info = manager.getActiveNetworkInfo();
			 if (info != null && info.isAvailable()) {
			     int nType = info.getType();
			     if(nType == ConnectivityManager.TYPE_MOBILE) type = TYPE_MOBILE;
			     else if(nType == ConnectivityManager.TYPE_WIFI) type = TYPE_WI_FI;
			 }
			 return type;
		} catch (Exception e) {			
			return TYPE_NONE;
		}
	}	
}
